<?php
namespace Admin\Controller;

class HeroController extends CommonController {
    public function index(){
        $this->assign('title','英雄管理');
        $list = M('icon');
        $data = $list->select();
        $this->assign('data',$data);
        $this->show();
    }
    public function edit(){
        // var_dump($_POST);die;
        $info = M('icon');
        $where['c_id'] = $_POST['c_id'];
        $re = $info->where($where)->save($_POST);
        $name = M('skill');
        $data['h_name'] = $_POST['h_name'];
        $res = $name->where($where)->save($data);
        if($res>0 && $re > 0 ){
        echo json_encode($re);
        }
    }
    public function d(){
        $del = M('icon');
        $re = $del->delete($_POST['c_id']);
        $del_skill = M('skill');
        $res = $del_skill->where('c_id='.$_POST['c_id'])->delete();
        if($re > 0 && $res > 0 ){
            echo json_encode($re);
        }

    }
    public function add(){
        $list = M('icon');
        $list->create();
        $re = $list->add();
        // var_dump($_POST);
        // var_dump($list);die;
        if($re>0){
        $_POST['c_id'] = $re;
        $skill = M('skill');
        // var_dump($_POST);die;
        $skill->create();
        $res = $skill->add();
        if($re>0 && $res>0){
                $this->success('添加成功');
            }else{
                return false;
            }
        }
}
}